home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / misc / edu / globe099src.lha / Ami-Globe / map_function.c < prev    next >
C/C++ Source or Header  |  1994-11-17  |  74KB  |  2,369 lines

  1. /************************************************************************/
  2. /*                                                                      */
  3. /*      fichier         : map_function.c                                */
  4. /*      projet          : amiglobe                                      */
  5. /*      date création   : 1993                                          */
  6. /*      commentaire     : fonctions de dessin de la carte               */
  7. /*      révision        : $VER: map_function.c 1.010 (14 Oct 1994)
  8. /*      copyright       : Olivier Collard, Thomas Landspurg             */
  9. /*      $HISTORY:                                                */
  10. /*                                                              */
  11. /*                     1993 : 0.01 : version initiale           */   
  12. /*                                                                      */
  13. /************************************************************************/
  14.  
  15.  
  16. /************************************************************************/
  17. /*      includes                                                        */
  18. /************************************************************************/
  19.         
  20. #include <exec/types.h>
  21. #include <exec/memory.h>
  22. #include <exec/libraries.h>
  23. #include <libraries/dos.h>
  24. #include <intuition/intuition.h>
  25. #include <graphics/gfxmacros.h>
  26. #include <datatypes/datatypes.h>
  27. #include <datatypes/datatypesclass.h>
  28. #include <datatypes/pictureclass.h>
  29. #include <graphics/displayinfo.h>
  30. #include <graphics/display.h>
  31. #include <graphics/gfxbase.h>
  32. #include <proto/dos.h>  /* pour DOSBase*/
  33. #include <libraries/fastsincos.h>
  34. #include <libraries/locale.h>
  35. #include "iff/jiff.h"
  36.  
  37. /* Prototypes */
  38. #include <clib/alib_protos.h>
  39. #include <clib/exec_protos.h>
  40. #include <clib/dos_protos.h>
  41. #include <clib/graphics_protos.h>
  42. #include <clib/intuition_protos.h>
  43. #include <clib/macros.h>
  44. #include <clib/datatypes_protos.h>
  45.  
  46. /* ANSI C */
  47. #include <stdlib.h>
  48. #include <string.h>
  49. #include <stdio.h>
  50. #include <ctype.h>
  51. #include <stat.h>
  52. #include <math.h>
  53.  
  54. //extern  struct Library *IntuitionBase;
  55. extern  struct GfxBase  *GfxBase;
  56. extern  struct Library *DataTypeBase;
  57. extern  struct Library *FastsincosBase;
  58. extern struct Locale * MyLocale;
  59.  
  60. #define REG(x) register __ ## x
  61. #define ASM    __asm
  62. #define SAVEDS __saveds
  63.  
  64. #include <pragmas/exec_pragmas.h>
  65. #include <pragmas/dos_pragmas.h>
  66. #include <pragmas/graphics_pragmas.h>
  67. #include <pragmas/intuition_pragmas.h>
  68.  
  69. #include "amiglobe_types.h"
  70. #include "database_types.h"
  71. #include "map_function_protos.h"
  72. #include "map_function_types.h"
  73. #include "main_protos.h"
  74. #include "database_protos.h"
  75. #include "3d_types.h"
  76. #include "3d_protos.h"
  77. #include "flag_protos.h"
  78. #include "iff_fct_protos.h"
  79. #include "divers.h"
  80. #include "projection.h"
  81.  
  82. /************************************************************************/
  83. /*      defines                                                         */
  84. /************************************************************************/
  85.  
  86.  
  87. /* Resolution minimum sans chargement */
  88.  
  89. #define MIN_RESO        3
  90.  
  91. /*
  92. #define DRAW
  93. */
  94. #define COLOR_BLEU              0
  95. #define COLOR_SELECT_PAYS       1
  96. #define COLOR_SELECT_SEG        2
  97. #define COLOR_COTE              1
  98. #define COLOR_TEXTE             3
  99. #define COLOR_LATLON            1
  100. #define COLOR_FOND_TEXTE        1
  101. #define COLOR_FOND_TEXTE_INFO   -1
  102. #define COLOR_TEXTE_INFO        -2
  103. #define COLOR_FRONTIERE         5
  104. #define COLOR_AFF_NOM_PAYS 6
  105.  
  106. #define COLOR_COAST             -1
  107. #define COLOR_COUNTRY           4
  108. #define COLOR_STATE             4
  109. #define COLOR_ISLANDS           2
  110. #define COLOR_LAKES             3
  111. #define COLOR_RIVERS            2
  112.  
  113. int     tab_look_up[]={ 
  114.                 0,
  115.                 COLOR_COAST , 
  116.                 COLOR_COUNTRY , 
  117.                 COLOR_COUNTRY , 
  118.                 COLOR_STATE , 
  119.                 COLOR_ISLANDS, 
  120.                 COLOR_LAKES,
  121.                 COLOR_RIVERS};
  122. int     nb_colors_free=12;
  123. int     num_first_color=4;
  124.  
  125. /************************************************************************/
  126. /*      variables externes                                              */
  127. /************************************************************************/
  128.  
  129. /*
  130. extern  struct IntuitionBase *IntuitionBase;
  131. */
  132. /*UWORD palette_glob[256];*/
  133. extern  struct  Screen  *sC;
  134.  
  135. extern  struct  Screen  *sC_Image;
  136. extern  BOOL continent_sel[6];
  137.  
  138.  
  139. Object  *Object_Fond=NULL;
  140.  
  141. static  E_Type_Graph    Glob_Type;
  142. /**********************************/
  143. /* Tableau des noms de continents */
  144. /**********************************/
  145.  
  146. char    *cont_name[]={"Europe","Africa","Asia","Oceania",
  147.             "South America","North America",NULL};
  148.  
  149.  
  150. CLIP    clip_max;
  151. CLIP    clip_proj;
  152.  
  153. int     cx=320;
  154. int     cy=100;
  155.  
  156. int     max_border=0;
  157.  
  158. /* Tableau de pointeurs sur les vecteurs */
  159.         
  160. BORDER  *tab_vect;
  161. COUNTRY *tab_country;
  162. TRAJECTOIRE ** tab_trajectoire;
  163. /* Pour le buffer circulaire */
  164.  
  165. int     *Tab_Seg_Loaded;
  166. int     Max_Loaded_Vect=100;
  167. int     Num_Cur=0;
  168. BPTR    bptr_big=NULL;
  169.  
  170. /*****************************/
  171.  
  172. #define DMAX    10
  173.  
  174. int     max_country=0;          /* Nombre max de pays       */
  175. int max_elem=0;
  176.  
  177. struct TextFont *Titre_Font_Glob=NULL;
  178. struct TextFont *Text_Font_Glob=NULL;
  179.  
  180. struct  ViewPort        *vp_glob;
  181.  
  182. /* Variables fournies de maniere externe...*/
  183. extern PREFERENCE Pref;
  184.  
  185. /*****************************************/
  186. /* Type de donnee pour le graphe courant */
  187. /*****************************************/
  188.  
  189. E_Type_Data     Type_Data_Glob;
  190.  
  191. /********************************************************************/
  192. /*      Implémentation                                              */
  193. /********************************************************************/
  194.  
  195.  
  196. /****************************************************************************/
  197. char    *get_pays_name(int num_pays)
  198. {
  199.         return(tab_country[num_pays].name);
  200. }
  201.  
  202. /****************************************************************************/
  203.  
  204. int     
  205. get_max_country(void)
  206. {
  207.         return(max_country);
  208. }
  209.  
  210. /****************************************************************************/
  211.  
  212. /****************************************************************************/
  213.  
  214. int     
  215. get_max_elem(void)
  216. {
  217.         return(max_elem);
  218. }
  219.  
  220. /****************************************************************************/
  221.  
  222. void    
  223. Map_Give_Type_Proj(E_TYPE_PROJ Type)
  224. {
  225.         Pref.Type_Proj=Type;
  226. }
  227.  
  228. /****************************************************************************/
  229.  
  230. void    
  231. Map_Give_Type_Trace(E_TYPE_TRACE Type)
  232. {
  233.         Pref.Type_Trace=Type;
  234. }
  235.  
  236. /****************************************************************************/
  237. /* Determine la meilleure profondeur en mode automatique, */
  238. /* ou retourne la profondeur choisie en mode non auto    */
  239. int     Find_Profondeur(int Prof)
  240. {
  241.     int     Prof_Ret;
  242.     int sx=(Pref.clip_cur.maxx-Pref.clip_cur.minx);
  243.  
  244.     /* En mode non automatique, on retourne direct */
  245.     if (Prof!=0)
  246.     {
  247.         Prof_Ret=Prof;
  248.     }
  249.     else
  250.     {
  251.         Prof_Ret= 2+ log((float)(sx/1000));
  252.     }
  253.     if (Prof_Ret<1)
  254.         Prof_Ret=1;
  255.     if (Prof_Ret>5)
  256.         Prof_Ret=5;
  257.     /*printf("Set Prof:%d\n",Prof_Ret);*/
  258.     return(Prof_Ret);
  259. }
  260.  
  261. /* Suite au chargement d'un nouveau border. libere un ancien    */
  262. /* border dans un buffer circulaire                             */
  263. void Free_Border(int In_Num_Vect)
  264. {
  265.     int     Old_Num;
  266.  
  267.     Old_Num=Tab_Seg_Loaded[Num_Cur];
  268.     if(Old_Num!=-1)
  269.     {
  270.         /*printf("  désallocation border n°%d",Old_Num);*/
  271.         FreeMem(tab_vect[Old_Num].p_vect_maxres,
  272.             (tab_vect[Old_Num].nb_vect_bis*sizeof(VECT)));
  273.         /*free(tab_vect[Old_Num].p_vect_maxres);*/
  274.         tab_vect[Old_Num].p_vect_maxres=NULL;
  275.     }
  276.     Tab_Seg_Loaded[Num_Cur]=In_Num_Vect;
  277.     Num_Cur=(Num_Cur+1)%Max_Loaded_Vect;
  278.     /*printf("  num_cur=%d\n",Num_Cur);*/
  279. }
  280.  
  281. /*********************************************************** check_border() ***/
  282.  
  283. /* Verifie si un border est charge (en tenant compte de la */
  284. /* resolution demandee) . Si le border n'est pas charge,   */
  285. /* on le charge.                                                                                   */
  286.  
  287. void check_border(int num_vect,int *Out_Nb_Vect,VECT **Out_P_Vect)
  288. {
  289.     BORDER  *current;
  290.     short   int     nb_vect;
  291.  
  292.     
  293.     current=&tab_vect[num_vect];
  294.  
  295.     *Out_Nb_Vect=current->nb_vect;
  296.     *Out_P_Vect=current->p_vect;
  297.  
  298.     if(Pref.prof<MIN_RESO)
  299.     {
  300.         /* il faut charger le border */
  301.         if(current->p_vect_maxres==NULL)
  302.         {
  303.             /* Si le segment n'avait jamais ete charge */
  304.             if(current->nb_vect_bis==-1)
  305.             {
  306.                     Seek(bptr_big,current->offset,OFFSET_BEGINNING);
  307.                     Read(bptr_big,&nb_vect,sizeof(short int));
  308.                     current->nb_vect_bis=nb_vect;
  309.             }
  310.             else
  311.             {
  312.                     Seek(bptr_big,current->offset+sizeof(short int),OFFSET_BEGINNING);
  313.                     nb_vect=current->nb_vect_bis;
  314.             }
  315.             current->p_vect_maxres=(VECT *)AllocMem(sizeof(VECT)*nb_vect,MEMF_CLEAR);
  316.             /*current->p_vect_maxres=(VECT *)malloc(sizeof(VECT)*nb_vect);*/
  317.             if(current->p_vect_maxres!=NULL)
  318.             {
  319.                     Read(bptr_big,current->p_vect_maxres,sizeof(VECT)*nb_vect);
  320.                     current->nb_vect_bis=nb_vect;
  321.                     Free_Border(num_vect);
  322.             }
  323.             else
  324.                 printf("ERROR: not enough memory\n");
  325.         }
  326.         if(current->p_vect_maxres!=NULL)
  327.         {
  328.                 *Out_Nb_Vect=current->nb_vect_bis;
  329.                 *Out_P_Vect=current->p_vect_maxres;
  330.         }
  331.     }
  332. }
  333.  
  334. /****************************************************************************/
  335. /* Converti un angle entier de -18000 à 18000 en un angle en radians */
  336. float   Map_Convert_Angle(int angle)
  337. {
  338.         float   f_angle;
  339.  
  340.         f_angle=((float)angle)*2*PI/((float)(clip_max.maxx-clip_max.minx));
  341.         return(f_angle);
  342. }
  343.  
  344. /****************************************************************************/
  345.  
  346. void    map_set_prof(int        profondeur)
  347. {
  348.         /*printf("profondeur:%d\n",profondeur);*/
  349.         Pref.prof_real=profondeur;
  350.         Pref.prof=Find_Profondeur(Pref.prof_real);
  351. }
  352.  
  353. /****************************************************************************/
  354. void init_map_datas(void)
  355. {
  356.         int i;
  357.         tab_vect=(BORDER *)malloc(sizeof(BORDER)*MAX_BORDER);
  358.         tab_country=(COUNTRY *)malloc(sizeof(COUNTRY)*MAX_COUNTRY);
  359.         Tab_Seg_Loaded=(int *)malloc(sizeof(int)*Max_Loaded_Vect);
  360.         tab_trajectoire=(TRAJECTOIRE **)malloc(sizeof(TRAJECTOIRE *)*MAX_TRAJECTOIRE);
  361.         tab_trajectoire[0]=NULL;
  362.         for(i=0;i<Max_Loaded_Vect;i++)Tab_Seg_Loaded[i]=-1;
  363. }
  364.  
  365. void    free_map_datas(void)
  366. {
  367.         int i;
  368.         if(bptr_big)Close(bptr_big);
  369.         for (i=0;i<max_country;i++)
  370.                 delete_element(tab_country[i].P_Elem_Rem);
  371. }
  372.  
  373. /****************************************************************************/
  374. void    give_size_window(int sx,int sy)
  375. {
  376.         Pref.win_width=sx;
  377.         Pref.win_height=sy;
  378.     /*printf("changement taille fenêtre:x=%d  y=%d \n",sx,sy);*/
  379. }
  380.  
  381.  
  382. /****************************************************************************/
  383.  
  384. void Map_Put_Million(char *In_Buffer,char *P_Format,int data)
  385. /* met dans In_Buffer P_Format avec le %s remplace par la string data */
  386. {
  387.    char Buffer[80];
  388.    int n,data_temp,nb;
  389.  
  390.    data_temp=data;
  391.    nb=log10(data)+1;
  392. /*   while (data_temp!=0)
  393.    {
  394.             nb++;
  395.             data_temp=data_temp/10;
  396.    }*/
  397.    nb += (nb) / 3 - 1;
  398.    Buffer[nb+1]=0;
  399.    Buffer[0]=' ';
  400.    n=3;
  401.  
  402.    while (data!=0)
  403.    {
  404.      Buffer[nb]='0'+data%10;
  405.      data=data/10;
  406.      nb--;
  407.      n--;
  408.      if( (n==0) && (data!=0) )
  409.      {
  410.             if (MyLocale!=NULL)
  411.                 Buffer[nb]=MyLocale->loc_GroupSeparator[0];
  412.             else
  413.                 Buffer[nb]=',';
  414.             nb--;
  415.             n=3;
  416.      }
  417.    }
  418.    sprintf(In_Buffer,P_Format,Buffer);
  419. }
  420.  
  421. /****************************************************************************/
  422.  
  423. void IPrint_NoAtt(
  424.         struct  RastPort *rpG,
  425.         int     x,
  426.         int     y,
  427.         char    *p_texte
  428.         )
  429. {
  430.         if(
  431.                 (x>0)&&
  432.                 (x<Pref.win_width)&&
  433.                 (y>0)&&
  434.                 (y<Pref.win_height))
  435.         {
  436.                 Move(rpG,x,y);
  437.                 Text(rpG,p_texte,strlen(p_texte));
  438.         }
  439. }
  440.  
  441. /****************************************************************************/
  442.  
  443.  
  444. void IPrintFond(
  445.         struct  RastPort *rpG,
  446.         int     x,
  447.         int     y,
  448.         char    *p_texte,
  449.         int     In_Color
  450.         )
  451. {
  452.         if(In_Color==-1)In_Color=COLOR_TEXTE;
  453.         SetAPen(rpG,In_Color+num_first_color);
  454.         SetDrMd(rpG,JAM1);
  455.         Move(rpG,x,y);
  456.         Text(rpG,p_texte,strlen(p_texte));
  457. }
  458.  
  459. void IPrint(
  460.         struct  RastPort *rpG,
  461.         int     x,
  462.         int     y,
  463.         char    *p_texte,
  464.         int     In_Color
  465.         )
  466. {
  467.         if(In_Color==-1)In_Color=-num_first_color+1;
  468.         SetAPen(rpG,In_Color+num_first_color);
  469.         SetBPen(rpG,0L);
  470.         SetDrMd(rpG,JAM2);
  471.         Move(rpG,x,y);
  472.         Text(rpG,p_texte,strlen(p_texte));
  473. /*      IPrint_NoAtt(rpG,x,y,p_texte);*/
  474. }
  475.  
  476. /****************************************************************************/
  477.  
  478. /*void TPrint(
  479.         struct  RastPort *rpG,
  480.         int     x,
  481.         int     y,
  482.         char    *p_texte,
  483.         int couleur_texte,
  484.         int couleur_fond
  485.         )
  486. {
  487.         SetAPen(rpG,couleur_texte);
  488.         SetBPen(rpG,couleur_fond);
  489.         SetDrMd(rpG,JAM2);
  490.         Move(rpG,x,y);
  491.         Text(rpG,p_texte,strlen(p_texte));
  492. }*/
  493.  
  494. /****************************************************************************/
  495.  
  496. void aff_country(int    num_pays,struct RastPort *rpG)
  497. {
  498.         CLIP    old_clip;
  499. /*      float   sx,sy;
  500.         float   h1,w1;*/
  501.  
  502. /*      char buffer[100];*/
  503.  
  504.         old_clip = Pref.clip_cur;
  505.  
  506.         Pref.clip_cur.minx=tab_country[num_pays].c_clip.minx-50;
  507.         Pref.clip_cur.miny=tab_country[num_pays].c_clip.miny-50;
  508.         Pref.clip_cur.maxx=tab_country[num_pays].c_clip.maxx+50;
  509.         Pref.clip_cur.maxy=tab_country[num_pays].c_clip.maxy+50;
  510.  
  511.         /*************************/
  512.         /* Affichage de la carte */
  513.         /*************************/
  514. /*      sx=(float)(Pref.clip_cur.maxx-Pref.clip_cur.minx);
  515.         sy=(float)(Pref.clip_cur.maxy-Pref.clip_cur.miny);
  516.  
  517.         h1=  Pref.win_width*sx*(clip_max.maxy-clip_max.miny)/
  518.             ((clip_max.maxx-clip_max.minx)*sy);
  519.         w1= Pref.win_height*sy*(clip_max.maxx-clip_max.minx)/((clip_max.maxy-clip_max.miny)*sx);
  520.  
  521.         if (h1<=Pref.win_height)
  522.     {
  523.                 Pref.win_width=(Pref.win_width*h1)/Pref.win_height;
  524.         }
  525.     else
  526.     {
  527.                 Pref.win_height=(Pref.win_height*w1)/Pref.win_width;
  528.         }
  529. */
  530.         SetRast(rpG,COLOR_BLEU+num_first_color);
  531.         WaitBlit();
  532.         /*Map_Aff_LatLon(rpG);*/
  533.         fill_country (num_pays,COLOR_STATE,rpG);
  534. /*      IPrint(rpG,50,20,buffer); */  /* ????? */
  535.  
  536.         Pref.clip_cur=old_clip;
  537. }
  538.  
  539.  
  540. /****************************************************************************/
  541.  
  542. void
  543. aff_info_page1(int      num_pays,struct RastPort *rpG)
  544. /* ,int cartex,int cartey*/
  545. {
  546.     char buffer[100];
  547.     ELEM_REM * nom_capitale;
  548.     int     posx,posy;
  549.  
  550.     /* On recupere la position de la carte */
  551.     if (Pref.win_width*sC->Height>sC->Width*Pref.win_height)
  552.     {
  553.         posx=5;
  554.         posy=Pref.win_height+10;
  555.     }
  556.     else
  557.     {
  558.         posx=Pref.win_width+5;
  559.         posy=15;
  560.     }
  561.         SetAPen(rpG,1L);        /*COLOR_TEXTE_INFO+num_first_color);*/
  562.         SetBPen(rpG,0L);    /*COLOR_FOND_TEXTE_INFO+num_first_color);*/
  563.         SetDrMd(rpG,JAM1);
  564.     if (Titre_Font_Glob)
  565.         SetFont(rpG,Titre_Font_Glob);
  566.     SetSoftStyle(rpG,(FSF_BOLD | FSF_UNDERLINED | FSF_ITALIC),(FSF_BOLD ));
  567.         /* lecture des donnees */
  568.         sprintf(buffer,"Official Name:%s",tab_country[num_pays].off_name);
  569.         IPrint(rpG,posx,posy,buffer,-1);
  570.         if (Text_Font_Glob)
  571.         SetFont(rpG,Text_Font_Glob);
  572.                 Map_Put_Million(buffer,"Population: %s",tab_country[num_pays].population);
  573.         IPrint(rpG,posx,posy+Text_Font_Glob->tf_YSize+2,buffer,-1);
  574.  
  575.         sprintf(buffer,"Continent: %s",cont_name[tab_country[num_pays].continent]);
  576.         IPrint(rpG,posx,posy+2*Text_Font_Glob->tf_YSize+2,buffer,-1);
  577.         Map_Put_Million(buffer,"Area: %s Km²",tab_country[num_pays].superficie);
  578.         IPrint(rpG,posx,posy+3*Text_Font_Glob->tf_YSize+2,buffer,-1);
  579.         if (tab_country[num_pays].superficie!=0)
  580.         {
  581.                 sprintf(buffer, "Density: %d inh./km²",
  582.                   (tab_country[num_pays].population)/
  583.                         (tab_country[num_pays].superficie));
  584.                 IPrint(rpG,posx,posy+4*Text_Font_Glob->tf_YSize+2,buffer,-1);
  585.         }
  586.         nom_capitale=capitale(num_pays);
  587.         if (nom_capitale!=NULL)
  588.         {
  589.                 sprintf(buffer,"Capital: %s (%d hab)",nom_capitale->Nom,
  590.                                 nom_capitale->caracteristique);
  591.                 IPrint(rpG,posx,posy+5*Text_Font_Glob->tf_YSize+2,buffer,-1);
  592.         }
  593.         Map_Put_Million(buffer,"Gross nat. product: M$%s",
  594.                 tab_country[num_pays].PIB);
  595.         IPrint(rpG,posx,posy+6*Text_Font_Glob->tf_YSize+2,buffer,-1);
  596.         if(tab_country[num_pays].population!=0)
  597.         {
  598.                 Map_Put_Million(buffer,"GNP per capita:$ %s",
  599.                   (int)(((float)tab_country[num_pays].PIB*1000000)/
  600.                             (tab_country[num_pays].population)));
  601.                 IPrint(rpG,posx,posy+7*Text_Font_Glob->tf_YSize+2,buffer,-1);
  602.         }
  603. }
  604.  
  605. /******************************************************** aff_info() ******/
  606.  
  607. void
  608. aff_info(int num_pays,struct RastPort *rpG,struct Window * window1)
  609. {
  610.     CLIP        My_Clip;
  611.     static char Buffer[90];
  612.     char Filename[50];
  613.     int clipx,clipy; /*dimension du clip du pays sélectionné*/        
  614.     int *P_Tab_Drapeau;
  615.     int Flg_Width,Flg_Height;
  616.     PREFERENCE Old_Pref=Pref;
  617.     Application_Sleep(TRUE);
  618.     /* Fenêtre dans laquelle se dessine le pays*/
  619.     if (num_pays!=-1)
  620.     {
  621.         sprintf(Buffer,"Info about:%s",tab_country[num_pays].name);
  622.         SetWindowTitles(window1,Buffer,(UBYTE *)~0);
  623.         clipx=tab_country[num_pays].c_clip.maxx-
  624.                         tab_country[num_pays].c_clip.minx;
  625.         clipy=tab_country[num_pays].c_clip.maxy-
  626.                         tab_country[num_pays].c_clip.miny;
  627.         if ( (float)(clipx / clipy) > 1.2)
  628.         {
  629.             if ( (float)(clipx / clipy) > 2.4)
  630.             {
  631.                 /* pays très large*/
  632.                 /*printf("pays très large  %d  %d\n",clipx,clipy);*/
  633.                 give_size_window((int)(window1->Width*0.8),
  634.                                 (int)(window1->Height*0.4));
  635.             }
  636.             else
  637.             {
  638.                 /* pays plus large que haut*/
  639.                 /*printf("pays plus large que haut  %d  %d\n",clipx,clipy);*/
  640.                 give_size_window((int)(window1->Width*0.7),
  641.                                 (int)(window1->Height*0.5));
  642.             }
  643.         }
  644.         else
  645.         {
  646.             if ( (float)(clipx / clipy) < 0.6)
  647.             {
  648.                 /*printf("pays très haut  %d  %d\n",clipx,clipy);*/
  649.                 give_size_window((int)(window1->Width*0.4),
  650.                              (int)(window1->Height*0.8));
  651.             }
  652.             else
  653.             {
  654.                 /*printf("pays plus haut que large  %d  %d\n",clipx,clipy);*/
  655.                 give_size_window((int)(window1->Width*0.5),
  656.                                 (int)(window1->Height*0.7));
  657.             }
  658.         }
  659.         /* affichage de la carte                                     */
  660.         Pref.prof=Find_Profondeur(2+(int)log((float)(clipx*.3/Pref.win_width)));
  661.         Pref.Flg_Aff_Elem_Rem=FALSE;
  662.         aff_country (num_pays,rpG);
  663.         /* la carte s'affiche en bleu et le reste est rempli en gris */
  664.         /* s'il y a des rivières qui s'"échappent" par exemple       */
  665.         SetAPen(rpG,0);
  666.         RectFill(rpG,Pref.win_width,0,
  667.                 window1->Width-window1->BorderRight-window1->BorderLeft,
  668.                 window1->Height-window1->BorderBottom-window1->BorderTop);
  669.         RectFill(rpG,0,Pref.win_height,Pref.win_width,
  670.                 window1->Height-window1->BorderTop-window1->BorderBottom);
  671.         /* cadre noir autour de la carte                             */
  672.         SetAPen(rpG,1);
  673.         Move(rpG,0,Pref.win_height);
  674.         Draw(rpG,Pref.win_width,Pref.win_height);
  675.         Draw(rpG,Pref.win_width,0);
  676.         /* affichage des infos (texte)                               */
  677.         aff_info_page1 (num_pays,rpG);
  678.         Pref.prof = Find_Profondeur(Pref.prof_real);
  679.     }
  680.     sprintf(Filename,"flags/%s.flag",tab_country[num_pays].name);
  681.     /* Affichage du drapeau du pays, s'il y en a un */
  682.     if(Flag_Read(Filename,&P_Tab_Drapeau))
  683.     {
  684.         Flg_Width  =window1->Width*0.2;
  685.         /* garde le meme aspect en pixels carres/pas carres */
  686.         Flg_Height =Flg_Width*2/3*640*sC->Height/(512*sC->Width);
  687.         
  688.         My_Clip.minx=window1->Width-Flg_Width*1.1-20;
  689.         My_Clip.maxx=window1->Width-Flg_Width*.1-20;
  690.         My_Clip.miny=window1->Height-Flg_Height*1.1-20;
  691.         My_Clip.maxy=window1->Height-Flg_Height*.1-20;
  692.  
  693.         IPrint(rpG,My_Clip.minx,My_Clip.miny-Text_Font_Glob->tf_YSize-2,
  694.                                 "Flag",1);
  695.         WaitBlit();
  696.         Flag_Draw(rpG,&My_Clip,P_Tab_Drapeau,window1->WScreen->ViewPort.ColorMap);
  697.  
  698.         free(P_Tab_Drapeau);        
  699.     }
  700.     Application_Sleep(FALSE);
  701.     Pref=Old_Pref;
  702. }
  703.  
  704. /******************************************************** print_pays() ****/
  705.  
  706. void print_pays(struct  RastPort *rpG)
  707. {
  708.         int     i,posx,posy;
  709.         posx=0;
  710.         posy=0;
  711.         for (i=0;i<max_country;i++)
  712.     {
  713.                 if (posy>8)
  714.         {
  715.                         posy=0;
  716.                         posx++;
  717.                 }
  718.                 Move(rpG,10+posx*100,20+posy*10);
  719.                 Text(rpG,tab_country[i].name,strlen(tab_country[i].name));
  720.                 posy++;
  721.         }
  722. }
  723.  
  724.  
  725. /* typedef pour les MyArea....                                  */      
  726. /* indique si le dernier point était sorti de   */
  727. /* l'écran et qu'il a fallu le projeter                 */
  728. typedef enum {AUCUN,HAUT,BAS,GAUCHE,DROITE}     CHECKXY;
  729. CHECKXY check=AUCUN;
  730.  
  731. /****************************************************************************/
  732. void check_xy( 
  733.         int * x,
  734.         int * y)
  735. {
  736.         if ((*x)>Pref.clip_cur.maxx)
  737.                 (*x)=Pref.clip_cur.maxx;
  738.         if ((*x)<Pref.clip_cur.minx)
  739.                 (*x)=Pref.clip_cur.minx;
  740.         if ((*y)>Pref.clip_cur.maxy)
  741.                 (*y)=Pref.clip_cur.maxy;
  742.         if ((*y)<Pref.clip_cur.miny)
  743.                 (*y)=Pref.clip_cur.miny;
  744. }
  745.  
  746. /****************************************************************************/
  747. CHECKXY check_xy_win(
  748.         int * x,
  749.         int * y)
  750. {
  751.         CHECKXY renvoi=AUCUN;
  752.         if((*x)<0)
  753.         {
  754.                 *x=0;
  755.                 /*printf("g");*/
  756.                 renvoi=GAUCHE;
  757.         }
  758.         if((*y)<0)
  759.         {
  760.                 *y=0;
  761.                 /*printf("h");*/
  762.                 renvoi=HAUT;
  763.         }
  764.         if((*x)>Pref.win_width-1 )
  765.         {
  766.                 *x=Pref.win_width-1;
  767.                 /*printf("d");*/
  768.                 renvoi=DROITE;
  769.         }
  770.         if((*y)>Pref.win_height-1)
  771.         {
  772.                 *y=Pref.win_height-1;
  773.                 /*printf("b");*/
  774.                 renvoi=BAS;
  775.         }
  776.         return renvoi;
  777. }
  778.         
  779. /****************************************************************************/
  780. void MyDraw(
  781.         struct  RastPort *rpG,
  782.         int     x,
  783.         int     y,
  784.         int     code
  785.         )
  786. {
  787.  
  788.         if (code>=Pref.prof)
  789.     {
  790.                 conv_xy(&x,&y);
  791.                 Draw(rpG,x,y);
  792.         }
  793. }
  794.  
  795. /****************************************************************************/
  796.  
  797. void
  798. MyMove(struct  RastPort *rpG,int x,int y)
  799. {
  800.         conv_xy(&x,&y);
  801.         Move(rpG,x,y);
  802. }
  803.  
  804. /****************************************************************************/
  805. void 
  806. MyAreaDraw(struct  RastPort *rpG,int x,int y,int code)
  807. {
  808.     if(code>=Pref.prof)
  809.     {
  810.         CHECKXY aux;
  811.         /*check_xy(&x,&y);*/
  812.         conv_xy(&x,&y);
  813.         aux=check_xy_win(&x,&y);
  814.         if (aux==AUCUN)
  815.         {
  816.             AreaDraw(rpG,x,y);
  817.         }
  818.         else
  819.         {
  820.             switch (check)
  821.                         {
  822.                         case HAUT:
  823.                                 switch(aux)
  824.                                 {
  825.                                 case GAUCHE:
  826.                                         AreaDraw(rpG,0,0);
  827.                                         break;
  828.                                 case DROITE:
  829.                                         AreaDraw(rpG,Pref.win_width,0);
  830.                                         break;
  831.                                 default:
  832.                                     break;
  833.                                 }
  834.                         break;
  835.                         case BAS:
  836.                                 switch(aux)
  837.                                 {
  838.                                 case GAUCHE:
  839.                                         AreaDraw(rpG,0,Pref.win_height);
  840.                                         break;
  841.                                 case DROITE:
  842.                                         AreaDraw(rpG,Pref.win_width,Pref.win_height);
  843.                                         break;
  844.                                 default:
  845.                                     break;  
  846.                                 }
  847.                         break;
  848.                         case GAUCHE:
  849.                                 switch(aux)
  850.                                 {
  851.                                 case HAUT:
  852.                                         AreaDraw(rpG,0,0);
  853.                                         break;
  854.                                 case BAS:
  855.                                         AreaDraw(rpG,0,Pref.win_height);
  856.                                         break;
  857.                                 default:
  858.                                     break;  
  859.                                 }
  860.                         break;
  861.                         case DROITE:
  862.                                 switch(aux)
  863.                                 {
  864.                                 case HAUT:
  865.                                         AreaDraw(rpG,Pref.win_width,0);
  866.                                         break;
  867.                                 case BAS:
  868.                                         AreaDraw(rpG,Pref.win_width,Pref.win_height);
  869.                                         break;
  870.                                 default:
  871.                                     break;  
  872.                                 }
  873.                         break;
  874.                         default:
  875.                         break;
  876.                         }
  877.                         AreaDraw(rpG,x,y);
  878.                 }
  879.                 check=aux;
  880.         }
  881. }
  882.  
  883. /****************************************************************************/
  884.  
  885. void MyAreaMove(
  886.         struct  RastPort *rpG,
  887.         int     x,
  888.         int     y
  889.         )
  890. {               
  891. /*      check_xy(&x,&y);*/
  892.         conv_xy(&x,&y);
  893.         check_xy_win(&x,&y);
  894.         AreaMove(rpG,x,y);
  895.         check=AUCUN;
  896. }
  897.  
  898.  
  899. /****************************************************************************/
  900.  
  901. void 
  902. MyAreaEnd(struct  RastPort *rpG)
  903. {
  904.     AreaEnd(rpG);
  905.     /*printf("\n");*/
  906. }
  907.  
  908.         
  909.         
  910. /****************************************************************************/
  911.  
  912. void
  913. map_draw_rect(struct  RastPort *rpG,int x,int y,int sx,int sy)
  914. {
  915.         Move(rpG,x,y);
  916.         Draw(rpG,x+sx,y);
  917.         Draw(rpG,x+sx,y+sy);
  918.         Draw(rpG,x,y+sy);
  919.         Draw(rpG,x,y);
  920. }
  921.  
  922.  
  923.  
  924. /****************************************************************************/
  925.  
  926. int
  927. find_country(int x,int y)
  928. {
  929.     int i,num_country;
  930.     COUNTRY *p_c;
  931.     int     current_size,size;
  932.     current_size =
  933.         (clip_max.maxx-clip_max.minx)*(clip_max.maxy-clip_max.miny);
  934.     num_country=-1;
  935.     conv_inv_xy(&x,&y);
  936.     for (i=0;i<max_country;i++)
  937.     {
  938.         p_c=&tab_country[i];
  939.         /* On cherche le pays le plus petit inclus dans son rectangle*/
  940.         if ( (x<p_c->c_clip.maxx) && (x>p_c->c_clip.minx) &&
  941.             (y<p_c->c_clip.maxy) && (y>p_c->c_clip.miny))
  942.         {
  943.             size=(p_c->c_clip.maxx-p_c->c_clip.minx)*
  944.                 (p_c->c_clip.maxy-p_c->c_clip.miny) ;
  945.  
  946.             if (size<current_size)
  947.             {
  948.                 num_country=i;
  949.                 current_size=size;
  950.             }
  951.         }
  952.     }
  953.     return(num_country);
  954. }
  955.  
  956. /*************************************************************************/
  957. /* Cherche un segment dans la table des vecteurs. Le parametre deep permet*/
  958. /* de definier une "profondeur de recherche, c.a.d. de trouver un segment*/
  959. /* sous un autre.                                                                                    */
  960. /*************************************************************************/
  961.  
  962. int map_find_segment(
  963.         int     x,
  964.         int     y
  965.         )
  966. {
  967.         int i,num_segment;
  968.         BORDER *p_b;
  969.         int     current_size,size;
  970.         int     errx,erry;
  971.         int     x0,y0;
  972.         int     x1,y1;
  973.  
  974.         num_segment=-1;
  975.         current_size=(clip_max.maxx-clip_max.minx)
  976.             *(clip_max.maxy-clip_max.miny);
  977.         conv_inv_xy(&x,&y);
  978.  
  979.         x0=0;y0=0;
  980.         x1=1;y1=1;
  981.         conv_inv_xy(&x0,&y0);
  982.         conv_inv_xy(&x1,&y1);
  983.         errx=x1-x0;
  984.         erry=y1-y0;
  985.  
  986.         for (i=0;(i<max_border);i++)
  987.     {
  988.                 p_b=&tab_vect[i];
  989.                 if( ( x >= p_b->b_clip.minx-errx ) &&
  990.                     ( x <= p_b->b_clip.maxx+errx ) &&
  991.                     ( y >= p_b->b_clip.miny-erry ) &&
  992.                     ( y <= p_b->b_clip.maxy+erry ) )
  993.         {
  994.  
  995.                         size=   (p_b->b_clip.maxx-p_b->b_clip.minx)*
  996.                                 (p_b->b_clip.maxy-p_b->b_clip.miny) ;
  997.  
  998.                         if (size<current_size)
  999.             {
  1000.                                 num_segment=i;
  1001.                                 current_size=size;
  1002.                         }
  1003.                 }
  1004.         }
  1005.         return(num_segment);
  1006. }
  1007.  
  1008. /****************************************************************************/
  1009.  
  1010. void map_draw_segment(
  1011.         struct  RastPort        *rpG,
  1012.         int     num_seg,
  1013.         int     color
  1014.         )
  1015. {
  1016.         int j;
  1017.         int nb_vect;
  1018.         VECT    *v;
  1019.  
  1020.         SetAPen(rpG,color+num_first_color);
  1021.  
  1022.         check_border(num_seg,&nb_vect,&v);              
  1023. /* tab_vect[num_seg].p_vect[j].xxx sont les coordonnees des segments */
  1024.         MyMove(rpG,v[0].x,v[0].y);
  1025.         for (j=1;j<nb_vect;j++)
  1026.     {
  1027.                 MyDraw(rpG,v[j].x,v[j].y,v[j].Code);
  1028.         }
  1029.  
  1030. }
  1031.  
  1032. /****************************************************************************/
  1033. int
  1034. tst_end( FILE    *input)
  1035. {
  1036.         char c;
  1037.         int     code_ret;
  1038.  
  1039.         /* lecture du prochain caractere */
  1040.         do
  1041.     {
  1042.                 c=getc(input);
  1043.                 if(c==EOF)return(TRUE);
  1044.                 if(c=='#')
  1045.         {
  1046.                         do
  1047.             {
  1048.                                 c=getc(input);
  1049.                         }
  1050.               while ((c!=0x0a)&&(c!=EOF));
  1051.                         c=getc(input);
  1052.                 }
  1053.  
  1054.         }
  1055.       while((!isalnum(c))&&(c!='E'));
  1056.         if ((!isalpha(c))||(c!='E'))
  1057.     {
  1058.                 ungetc(c,input);
  1059.                 code_ret=FALSE;
  1060.         }
  1061.     else
  1062.     {
  1063.                 code_ret=TRUE;
  1064.         }
  1065.         return(code_ret);
  1066. }
  1067.  
  1068. /****************************************************************************/
  1069.  
  1070. void tstpt(
  1071.         int     x,
  1072.         int     y,
  1073.         int     *pmx,
  1074.         int     *pmy,
  1075.         int     *pMX,
  1076.         int     *pMY
  1077.         )
  1078. {
  1079.         if (x<*pmx)
  1080.     {
  1081.                 *pmx=x;
  1082.         }
  1083.         if (x>*pMX)
  1084.     {
  1085.                 *pMX=x;
  1086.         }
  1087.         if (y<*pmy)
  1088.     {
  1089.                 *pmy=y;
  1090.         }
  1091.         if (y>*pMY)
  1092.     {
  1093.                 *pMY=y;
  1094.         }
  1095. }
  1096. /****************************************************************************/
  1097.  
  1098. int     
  1099. tstclip( int mx, int my,int  MX, int MY, CLIP *p_clip)
  1100. {
  1101.     if (Pref.Type_Proj==PROJ_GLOBE)
  1102.     {
  1103.         float centrex=Map_Convert_Angle((mx+MX)/2);
  1104.         float centrey=Map_Convert_Angle((my+MY)/2);
  1105.         float largeur=Map_Convert_Angle((clip_proj.maxx-clip_proj.minx)/2);
  1106.         //float hauteur=Map_Convert_Angle((clip_proj.maxy-clip_proj.miny)/2);
  1107.         float minx=Map_Convert_Angle(p_clip->minx);
  1108.         float maxx=Map_Convert_Angle(p_clip->maxx);
  1109.         float miny=Map_Convert_Angle(p_clip->miny);
  1110.         float maxy=Map_Convert_Angle(p_clip->maxy);
  1111.         if (largeur>PI/2)
  1112.             largeur=PI/2;
  1113.         if (FastsincosBase!=NULL)
  1114.         {
  1115.             if (acos(fastsin(miny)*fastsin(centrey)+
  1116.                 fastcos(miny)*fastcos(centrey)*fastcos(minx-centrex))<largeur)
  1117.                 return TRUE;
  1118.             else
  1119.             if (acos(fastsin(miny)*fastsin(centrey)+
  1120.                 fastcos(miny)*fastcos(centrey)*fastcos(maxx-centrex))<largeur)
  1121.                 return TRUE;
  1122.             else
  1123.             if (acos(fastsin(maxy)*fastsin(centrey)+
  1124.                 fastcos(maxy)*fastcos(centrey)*fastcos(minx-centrex))<largeur)
  1125.                 return TRUE;
  1126.             else
  1127.             if (acos(fastsin(maxy)*fastsin(centrey)+
  1128.                 fastcos(maxy)*fastcos(centrey)*fastcos(maxx-centrex))<largeur)
  1129.                 return TRUE;
  1130.             else
  1131.                 return FALSE;
  1132.         }
  1133.         else
  1134.         {
  1135.             if (acos(sin(miny)*sin(centrey)+
  1136.                 cos(miny)*cos(centrey)*cos(minx-centrex))<largeur)
  1137.                 return TRUE;
  1138.             else
  1139.             if (acos(sin(miny)*sin(centrey)+
  1140.                 cos(miny)*cos(centrey)*cos(maxx-centrex))<largeur)
  1141.                 return TRUE;
  1142.             else
  1143.             if (acos(sin(maxy)*sin(centrey)+
  1144.                 cos(maxy)*cos(centrey)*cos(minx-centrex))<largeur)
  1145.                 return TRUE;
  1146.             else
  1147.             if (acos(sin(maxy)*sin(centrey)+
  1148.                 cos(maxy)*cos(centrey)*cos(maxx-centrex))<largeur)
  1149.                 return TRUE;
  1150.             else
  1151.                 return FALSE;
  1152.          }
  1153.     }
  1154.     else
  1155.     if ((mx>p_clip->maxx)||(MX<p_clip->minx)||
  1156.         (my>p_clip->maxy)||(MY<p_clip->miny))
  1157.     {
  1158.         return FALSE;
  1159.     }
  1160.     else
  1161.     {
  1162.         return TRUE;
  1163.     }
  1164. }
  1165.  
  1166.  
  1167. /***************************************************** reset_bord() *****/
  1168.  
  1169. /************************************************/
  1170. /* Reinitialise les drapeaux indiquant qu'un    */
  1171. /* bord a ete trace                             */
  1172. /************************************************/
  1173.  
  1174. void reset_bord(void)
  1175. {
  1176.         int     i;
  1177.         for(i=0;i<max_border;i++){
  1178.                 tab_vect[i].flg_draw=FALSE;
  1179.         }
  1180. }
  1181.  
  1182. /******************************************* map_aff_country_name() *****/
  1183.  
  1184. void
  1185. map_aff_country_name(COUNTRY * p_count,struct RastPort * rpG)
  1186. {
  1187.     int sx=(p_count->c_clip).maxx-(p_count->c_clip).minx;
  1188.     int SX=Pref.clip_cur.maxx-Pref.clip_cur.minx;
  1189.     int posx,posy;
  1190.     if (sx>0)
  1191.     {
  1192.         if ((SX/sx)<4)
  1193.         {
  1194.             posx=sx/2+(p_count->c_clip).minx;
  1195.             posy=(p_count->c_clip).maxy/2+(p_count->c_clip).miny/2;
  1196.             conv_xy(&posx,&posy);
  1197.             posx-=4*strlen(p_count->name);
  1198.             posy-=4;
  1199.  
  1200.             IPrint(rpG,posx,posy,p_count->name,
  1201.                     COLOR_AFF_NOM_PAYS+num_first_color);
  1202.         }
  1203.     }
  1204.     else
  1205.         {}
  1206.         /*printf("pays %s :sx nul\n",p_count->name);*/
  1207. }
  1208.  
  1209. /***************************************************** clear_map() *****/
  1210. void clear_map(struct RastPort *rpG)
  1211. {
  1212.     SetRast(rpG,COLOR_BLEU+num_first_color);
  1213.     if(Object_Fond!=NULL)
  1214.     {
  1215.         Iff_Copy_Fond(Object_Fond,rpG);
  1216.     }
  1217. }
  1218.  
  1219. /***************************************************** redraw_map() *****/
  1220.  
  1221. void 
  1222. redraw_map_fil(int     num_continent,struct  RastPort *rpG)
  1223. {
  1224.     struct RastPort *r;
  1225.     int     num_country;
  1226.     int     i,j;
  1227.     /* Vecteur courant */
  1228.     int     num_vect;
  1229.     COUNTRY *p_count;
  1230.     VECT    *V;
  1231.     BOOL    Flg_Draw;
  1232.     int     code;
  1233.     int     nb_vect;
  1234.  
  1235.     
  1236.     r = rpG;
  1237.     conv_clip();
  1238.     clear_map(rpG);
  1239.     SetBPen(r,COLOR_COTE+num_first_color);
  1240.     SetDrMd(r,JAM1);
  1241.  
  1242.     reset_bord();
  1243.     Map_Aff_LatLon(rpG);
  1244.  
  1245.     /********************************************/
  1246.     /* Pour tout les pays de la base de donnees */
  1247.     /********************************************/
  1248.  
  1249.     for (num_country=0;num_country<max_country;num_country++)
  1250.     {
  1251.  
  1252.         if (continent_sel[tab_country[num_country].continent]==TRUE)
  1253.         {
  1254.             /****************************************************/
  1255.             /* Pour un pays, on connait le nom, et le nombre de */
  1256.             /* bords                                            */
  1257.             /****************************************************/
  1258.  
  1259.             p_count=&tab_country[num_country];
  1260.             if (tstclip(        clip_proj.minx,clip_proj.miny,
  1261.                         clip_proj.maxx,clip_proj.maxy,&(p_count->c_clip)))
  1262.             {
  1263.                 Flg_Draw=TRUE;
  1264.                 for (i=0;i<p_count->nb_borders;i++)
  1265.                 {
  1266.             
  1267.                     /*********************************************/
  1268.                     /* Pour chaque bord, on affiche les vecteurs */
  1269.                     /* correspondants a ce bord                  */
  1270.                     /*********************************************/
  1271.                     num_vect=(p_count->p_borders)[i];
  1272.                     if (tstclip(        clip_proj.minx,clip_proj.miny,
  1273.                                 clip_proj.maxx,clip_proj.maxy,
  1274.                                 &(tab_vect[num_vect].b_clip)))
  1275.                     {
  1276.                         if (tab_vect[num_vect].flg_draw==FALSE)
  1277.                         {
  1278.                             tab_vect[num_vect].flg_draw=TRUE;
  1279.  
  1280.                             if (tab_vect[num_vect].p_vect[0].Code>1000)
  1281.                             {
  1282.                                     code=tab_vect[num_vect].p_vect[0].Code/1000;
  1283.                             }
  1284.                             if (((code==ID_LAC)&&(Pref.Flg_Draw_Lac==FALSE))
  1285.                                     ||((code==ID_RIVIERES)&&(Pref.Flg_Draw_Riv==FALSE)))
  1286.                             {}
  1287.                             else
  1288. /*
  1289.                             {
  1290.                                     Flg_Draw=FALSE;
  1291.                             }
  1292.                             if ((code==ID_RIVIERES)&&(Pref.Flg_Draw_Riv==FALSE))
  1293.                             {
  1294.                                     Flg_Draw=FALSE;
  1295.                             }
  1296.                               }
  1297.                             if (Flg_Draw)*/
  1298.                             {
  1299.                                 check_border(num_vect,&nb_vect,&V);
  1300.                                 switch (code)
  1301.                                 {
  1302.                                 case ID_LAC:
  1303.                                     SetAPen(r,COLOR_LAKES+num_first_color);
  1304.                                     break;
  1305.                                 case ID_RIVIERES:
  1306.                                     SetAPen(r,COLOR_RIVERS+num_first_color);
  1307.                                     break;
  1308.                                 case ID_ISLAND:
  1309.                                 case ID_COTE:
  1310.                                     SetAPen(r,COLOR_COAST+num_first_color);
  1311.                                     break;
  1312.                                 default:
  1313.                                     SetAPen(r,COLOR_FRONTIERE+num_first_color);
  1314.                                 }       
  1315.                                 MyMove(r,V[0].x,V[0].y);
  1316.                                 for (j=1;j<nb_vect;j++)
  1317.                                 {
  1318.                                     MyDraw(r,V[j].x,V[j].y,V[j].Code);
  1319.                                 }
  1320.                             }
  1321.                         }
  1322.                     }
  1323. /*                  Flg_Draw=TRUE;*/
  1324.                 }/* fin du for sur les borders      */
  1325.                 if (Pref.Flg_Aff_Country_Name==TRUE)
  1326.                 {
  1327.                     map_aff_country_name(p_count,rpG);
  1328.                 }
  1329.             }
  1330.         }
  1331.     }/* Fin du for sur les country          */
  1332.     reselect(rpG); /* remplissage du pays sélectionné*/
  1333. }
  1334.  
  1335. /****** Trace de la carte, mais en plein pour les pays */
  1336.  
  1337. void 
  1338. redraw_map_plein(int num_continent,struct  RastPort *rpG)
  1339. {
  1340.     int     i,max;
  1341.  
  1342.     max=get_max_country();
  1343.     clear_map(rpG);
  1344.     Map_Aff_LatLon(rpG);
  1345.     for (i=0;i<max;i++)
  1346.     {
  1347.     if (tab_country[i].continent==num_continent
  1348.         || num_continent==-1)
  1349.         fill_country(i,COLOR_STATE,rpG);
  1350.     }
  1351. }
  1352.  
  1353. /***************************************************** redraw_map() *****/
  1354.  
  1355. void 
  1356. redraw_map( int  num_continent, struct  RastPort  *rpG)
  1357. {
  1358.     /* fait dodo, application! */
  1359.     Application_Sleep(TRUE);
  1360.     Update_New_Clip();
  1361.     if(Pref.Type_Trace==TRACE_FIL)
  1362.     {
  1363.         redraw_map_fil(num_continent,rpG);
  1364.     }
  1365.     else
  1366.     {
  1367.         redraw_map_plein(num_continent,rpG);
  1368.     }
  1369.     /* il est l'heure de se lever */
  1370.     Application_Sleep(FALSE);
  1371. }
  1372.  
  1373. /***************************************************** redraw_map() *****/
  1374.  
  1375. void redraw_map_complete(
  1376.         struct  RastPort        *rpG
  1377.         )
  1378. {
  1379.         struct RastPort *r;
  1380.         int     i,j;
  1381.         /* Vecteur courant */
  1382.         VECT    *V;
  1383.  
  1384.         r = rpG;
  1385.         SetRast(r,COLOR_BLEU+num_first_color);
  1386.         if(sC_Image!=NULL){
  1387.                 ClipBlit( r, 0L, 0L,
  1388.                       sC_Image->FirstWindow->RPort, 0L, 0L,
  1389.                       Pref.win_width,
  1390.                       Pref.win_height,
  1391.                       (long)COPY_MINTERM);
  1392.         }
  1393.         SetAPen(r,num_first_color+COLOR_SELECT_SEG);
  1394.         SetBPen(r,COLOR_COTE+num_first_color);
  1395.         SetDrMd(r,JAM1);
  1396.  
  1397.         for(i=0;i<max_border;i++){
  1398.                 /*********************************************/
  1399.                 /* Pour chaque bord, on affiche les vecteurs */
  1400.                 /* correspondants a ce bord                  */
  1401.                 /*********************************************/
  1402.                 if(tstclip(     clip_proj.minx,clip_proj.miny,
  1403.                                 clip_proj.maxx,clip_proj.maxy,
  1404.                                 &(tab_vect[i].b_clip))){
  1405.  
  1406.                         V=tab_vect[i].p_vect;
  1407.                         SetAPen(r,tab_look_up[V[0].Code/1000]+num_first_color);
  1408.                         MyMove(r,V[0].x,V[0].y);
  1409.                         for(j=1;j<tab_vect[i].nb_vect;j++){
  1410.                                 MyDraw(r,V[j].x,V[j].y,V[j].Code);
  1411.                         }
  1412.                 }
  1413.         }
  1414. }
  1415.  
  1416. /*****************************************************  *****/
  1417.  
  1418. BOOL    
  1419. Est_Pres(int x1,int x2)
  1420. {
  1421.         
  1422.         if(ABS(x2-x1)<=20){
  1423.                 return( TRUE );
  1424.         }else{
  1425.                 return( FALSE );
  1426.         }
  1427. }
  1428.  
  1429. /*****************************************************  *****/
  1430.  
  1431. int     
  1432. Dist(int x1,int x2,int y1,int y2)
  1433. {
  1434.         
  1435.         return(ABS(x2-x1)+ABS(y2-y1));
  1436. }
  1437.  
  1438. /***************************************************** fill_country() *****/
  1439.  
  1440. void 
  1441. fill_country(int  num_country,int color,struct  RastPort  *rpG)
  1442. {
  1443.    struct RastPort *r;
  1444.    long lastx=0,lasty=0;        
  1445.    long firstx,firsty;
  1446.    int  first,dir;
  1447.    BOOL new_area;
  1448.    int  i,j;
  1449.    int  code,couleur;
  1450.    BOOL Flg_Draw;
  1451.    /* Vecteur courant */
  1452.    VECT *V;
  1453.    int  num_vect,nb_vect;
  1454.    COUNTRY      *p_count;
  1455.    int  Dist_Deb,Dist_Fin;
  1456.  
  1457.     code=0;
  1458.  
  1459.     p_count=&tab_country[num_country];
  1460.     if (tstclip(        Pref.clip_cur.minx,Pref.clip_cur.miny,
  1461.                 Pref.clip_cur.maxx,Pref.clip_cur.maxy,&(p_count->c_clip)))
  1462.     {
  1463.         r = rpG;
  1464.         SetAPen(r,(long)color+num_first_color);
  1465.         SetBPen(r,COLOR_COTE+num_first_color);
  1466.  
  1467. /*      SetOPen(r,COLOR_COAST+num_first_color);*/
  1468.  
  1469.         SetDrMd(r,JAM1);
  1470.  
  1471.         /****************************************************/
  1472.         /* Pour un pays, on connait le nom, et le nombre de */
  1473.         /* bords                                            */
  1474.         /****************************************************/
  1475.  
  1476.         new_area=TRUE;
  1477.  
  1478.         for (i=0;i<p_count->nb_borders;i++)
  1479.         {
  1480.             Flg_Draw=TRUE;
  1481.         
  1482.             /*********************************************/
  1483.             /* Pour chaque bord, on affiche les vecteurs */
  1484.             /* correspondants a ce bord                  */
  1485.             /*********************************************/
  1486.  
  1487.             /* nombre de vecteurs du bord */
  1488.             num_vect=(p_count->p_borders)[i];
  1489.  
  1490.             V=tab_vect[num_vect].p_vect;
  1491.             nb_vect=tab_vect[num_vect].nb_vect;
  1492.  
  1493.             if(V[0].Code>1000)
  1494.             {
  1495.                 code=V[0].Code/1000;
  1496.                 /* les lacs ne sont pas remplis */
  1497.                 if (code==ID_LAC)
  1498.                     Flg_Draw=FALSE;
  1499.                 /* les rivières seront dessinées après*/
  1500.                 if (code==ID_RIVIERES)
  1501.                     Flg_Draw=FALSE;
  1502.             }
  1503.             check_border(num_vect,&nb_vect,&V);
  1504.             if (new_area==TRUE)
  1505.             {
  1506.                 /* border suivant (s'il existe)*/
  1507.                 VECT    *V_Suivant;
  1508.                 int     num_vect1,nb_vect1;
  1509.                 if (i+1<p_count->nb_borders)
  1510.                 {
  1511.                     num_vect1=(p_count->p_borders)[i+1];
  1512.                     check_border(num_vect1,&nb_vect1,&V_Suivant);                           /* SI il y a plus d'un vecteur, on regarde le cas du */
  1513.                 }
  1514.                 dir=1;  /* direction dans laquelle on parcourt les vecteurs*/
  1515.                 first=0;/* numero du vecteur par lequel on commence        */
  1516.                 new_area=FALSE;
  1517.                 /* premier point                                                     */
  1518.         
  1519.                 if ((nb_vect>1)&&( i+1 < p_count->nb_borders))
  1520.                 {
  1521.  
  1522. /*                  nb_vect1=tab_vect[num_vect1].nb_vect;
  1523.                     V_Suivant=tab_vect[num_vect1].p_vect;*/
  1524.  
  1525.                     /* Si le dernier point du premier segment*/
  1526.                     /* egal au premier pt du segment suivant */
  1527.                     /* ou si le dernier pt du premier seg.   */
  1528.                     /* egal au dernier pt segmet suivant,    */
  1529.                     /* on parcours le premier segment en montant */
  1530.                     /* sinon on le parcours en descendant    */
  1531.  
  1532.  
  1533.                     if((Est_Pres( V[nb_vect-1].x,V_Suivant[0].x )&&
  1534.                         Est_Pres( V[nb_vect-1].y,V_Suivant[0].y ) ) ||
  1535.                        (Est_Pres( V[nb_vect-1].x,V_Suivant[nb_vect1-1].x)&&
  1536.                         Est_Pres( V[nb_vect-1].y,V_Suivant[nb_vect1-1].y)
  1537.                        ))
  1538.                     {
  1539.  
  1540.                         first=0;
  1541.                         dir=1;
  1542.                     }
  1543.                     else
  1544.                     {
  1545.                         first=nb_vect-1;
  1546.                         dir=-1;
  1547.                     }
  1548.                 }
  1549.                 firstx=V[first].x;
  1550.                 firsty=V[first].y;
  1551.                 if (Flg_Draw)
  1552.                     MyAreaMove(r,firstx,firsty);
  1553.             }
  1554.             else
  1555.             {
  1556.                 /************************************************/
  1557.                 /* Un bord a deja ete trace                             */
  1558.                 /* On regarde lequel des deux extremites            */
  1559.                 /* pt du segment suivant s'attachent a ce seg.  */
  1560.                 /************************************************/
  1561.  
  1562.                 Dist_Deb=Dist(lastx,V[0].x        ,lasty,V[0].y       );
  1563.                 Dist_Fin=Dist(lastx,V[nb_vect-1].x,lasty,V[nb_vect-1].y);
  1564.                 /* si min(Dist_Deb,Dist_Fin)>100,       */
  1565.                 /* les vecteurs sont trop loins,        */
  1566.                 /* il faut fermer l'ancienne zone       */
  1567.                 /* et en commencer une nouvelle         */
  1568.                 if (Dist_Deb<=Dist_Fin)
  1569.                 {
  1570.                     dir=1;
  1571.                     first=0;
  1572.                 }
  1573.                 else
  1574.                 {
  1575.                     dir=-1;
  1576.                     first=nb_vect-1;
  1577.                 }
  1578.             }
  1579.             /* On trace tous les vecteurs de ce segment */
  1580.             for (j=1;j<nb_vect;j++)
  1581.             {
  1582.                 first+=dir;
  1583.                 if (Flg_Draw)
  1584.                     MyAreaDraw(r,V[first].x,V[first].y,V[first].Code);
  1585.             }
  1586.  
  1587.             /* Pour rechercher le debut du prochain segment */
  1588.             lastx=V[first].x;
  1589.             lasty=V[first].y;
  1590.  
  1591.             /* Si on boucle, cela veut dire qu'il faut recommencer une nouvelle */
  1592.             /* aire (cas des iles par exemple                                   */
  1593.             if( (Est_Pres(lastx,firstx)&&Est_Pres(lasty,firsty) )||
  1594.                             (i== p_count->nb_borders-1))
  1595.             {
  1596.                 new_area=TRUE;
  1597.                 if (Flg_Draw)
  1598.                     MyAreaEnd(r);
  1599.             }
  1600. /*          else*/
  1601.             /* si le prochain border est trop loin, il recommencer  */
  1602.             /* une nouvelle aire                                                                    */
  1603. /*          if (i+1<p_count->nb_borders)
  1604.                 if (ABS(V[nb_vect-1].x-V_Suivant[0].x)
  1605.                         +ABS(V[nb_vect-1].y-V_Suivant[0].y) > 500
  1606.                         &&
  1607.                         ABS(V[nb_vect-1].x-V_Suivant[nb_vect1-1].x)
  1608.                         +ABS(V[nb_vect-1].y-V_Suivant[nb_vect1-1].y) > 500)
  1609.                 {
  1610.                         new_area=TRUE;
  1611.                         if (Flg_Draw)
  1612.                                 MyAreaEnd(r);
  1613.                 }       */                      
  1614.         }
  1615.         
  1616.         if (new_area==FALSE)
  1617.             MyAreaEnd(r);
  1618.  
  1619.         for (i=0;i<p_count->nb_borders;i++)
  1620.         {
  1621.             /* nombre de vecteurs du bord */
  1622.             num_vect=(p_count->p_borders)[i];
  1623.  
  1624.             V=tab_vect[num_vect].p_vect;
  1625. /*          nb_vect=tab_vect[num_vect].nb_vect;*/
  1626.  
  1627.             Flg_Draw=FALSE;
  1628.             if (V[0].Code>1000)
  1629.             {
  1630.                 code=V[0].Code/1000;
  1631.                 if ((code!=ID_COTE)&&(code!=ID_RIVIERES)&&(code!=ID_LAC))
  1632.                 {
  1633.                     Flg_Draw=TRUE;
  1634.                     couleur=COLOR_FRONTIERE;
  1635.                 }
  1636.                 if((code==ID_RIVIERES)&&(Pref.Flg_Draw_Riv==TRUE))
  1637.                 {
  1638.                         Flg_Draw=TRUE;
  1639.                         couleur=COLOR_LAKES;
  1640.                 }
  1641.                 if((code==ID_LAC)&&(Pref.Flg_Draw_Lac==TRUE))
  1642.                 {
  1643.                         Flg_Draw=TRUE;
  1644.                         couleur=COLOR_RIVERS;
  1645.                 }
  1646.                 if ((code==ID_COTE)||(code==ID_ISLAND))
  1647.                 {
  1648.                         Flg_Draw=TRUE;
  1649.                         couleur=COLOR_COAST;
  1650.                 }                               
  1651.             }
  1652.             if(Flg_Draw)
  1653.             {
  1654.         /*      if ( (Pref.Flg_Draw_Riv==TRUE)&& (code==ID_RIVIERES))*/
  1655.                 map_draw_segment(
  1656.                     rpG,
  1657.                     num_vect,
  1658.                     couleur);
  1659.             }
  1660.         }
  1661.         
  1662.         if (Pref.Flg_Aff_Country_Name==TRUE)
  1663.                 map_aff_country_name(p_count,rpG);
  1664.         if (Pref.Flg_Aff_Elem_Rem==TRUE)
  1665.                 aff_elem_rem(rpG,num_country);
  1666.     }
  1667. }
  1668.  
  1669. /*************************************************************************/
  1670.  
  1671. void    DrawSeg(struct  RastPort        *rpG,
  1672.                 VECT    tab_pt[],
  1673.                 int     pt1,
  1674.                 int     pt2,
  1675.                 int     pt3
  1676.                 )
  1677. {
  1678.         
  1679.         MyMove(rpG,tab_pt[pt1].x,tab_pt[pt1].y);
  1680.         MyDraw(rpG,tab_pt[pt2].x,tab_pt[pt2].y,tab_pt[pt2].Code);
  1681.         MyDraw(rpG,tab_pt[pt3].x,tab_pt[pt3].y,tab_pt[pt3].Code);
  1682. }
  1683.  
  1684.  
  1685.  
  1686. /*************************************************************************/
  1687.  
  1688. int     map_find_pt(
  1689.         struct  RastPort        *rpG,
  1690.         int     x,
  1691.         int     y,
  1692.         VECT    **pp_v,
  1693.         int     *p_num_pt,
  1694.         int     *p_num_border
  1695.         )
  1696. {
  1697.         int     flg_found,i,j,dx,dy;
  1698.         VECT    *v;
  1699.         int     dmaxx,dmaxy;
  1700.         int     x0,y0;
  1701.         int     x1,y1;
  1702.  
  1703.         i=0;
  1704.         flg_found=FALSE;
  1705.         /*printf("x:%d y:%d\n",x,y);*/
  1706.  
  1707.         conv_inv_xy(&x,&y);
  1708.  
  1709.         x0=x     ; y0=y;
  1710.         x1=y+DMAX; y1=y+DMAX;
  1711.  
  1712.         conv_inv_xy(&x0,&y1);
  1713.         conv_inv_xy(&x1,&y1);
  1714.         dmaxx=x1-x0;
  1715.         dmaxy=y1-y0;
  1716.  
  1717.         /*printf("x:%d y:%d\n",x,y);*/
  1718.         do{
  1719.            if(tstclip(  Pref.clip_cur.minx,Pref.clip_cur.miny,
  1720.                         Pref.clip_cur.maxx,Pref.clip_cur.maxy,&(tab_vect[i].b_clip))){
  1721.                 j=0;
  1722.                 v=tab_vect[i].p_vect;
  1723.  
  1724.                 do{
  1725.                         dx=x-v[j].x;
  1726.                         dy=y-v[j].y;
  1727. /*
  1728.                         printf("vx:%4d vy:%4d %4d %4d\n",v[j].x,v[j].y,dx,dy);
  1729. */
  1730.                         if((dx<dmaxx)&&(dx>-dmaxx)&&(dy<dmaxy)&&(dy>-dmaxy)){
  1731.                                 flg_found=TRUE;
  1732.                                 /*printf("Found pt!\n");*/
  1733.                                 *pp_v=&v[j];
  1734.                                 *p_num_pt=j;
  1735.                                 *p_num_border=i;
  1736.                                 SetAPen(rpG,num_first_color+COLOR_TEXTE);
  1737.                                 x0=v[j].x;
  1738.                                 y0=v[j].y;
  1739.                                 conv_xy(&x0,&y0);
  1740.                                 map_draw_rect(rpG,x0-10,y0-10,20,20);
  1741.                                 SetAPen(rpG,1L);
  1742.                         }
  1743.                         j++;
  1744.  
  1745.                 }while((j<tab_vect[i].nb_vect)&&(flg_found==FALSE));
  1746.              }
  1747.              i++;
  1748.         }while((i<max_border)&&(flg_found==FALSE));
  1749.         return(flg_found);
  1750. }
  1751.  
  1752. /*************************************************************************/
  1753.  
  1754. void    map_show_pt(struct      RastPort        *rpG)
  1755. {
  1756.         int     i,j;
  1757.         VECT    *v;
  1758.         int     x,y;
  1759.         int     nb_vect;
  1760.         
  1761.         SetDrMd(rpG,JAM2);
  1762.         SetAPen(rpG,10L);
  1763.         for(i=0;i<max_border;i++){
  1764.             if(tstclip( Pref.clip_cur.minx,Pref.clip_cur.miny,
  1765.                         Pref.clip_cur.maxx,Pref.clip_cur.maxy,&(tab_vect[i].b_clip))){
  1766.  
  1767.                 check_border(i,&nb_vect,&v);
  1768.                 for(j=0;j<tab_vect[i].nb_vect;j++){
  1769.                         x=v[j].x;
  1770.                         y=v[j].y;
  1771.                         conv_xy(&x,&y);
  1772.                         map_draw_rect(rpG,x-2,y-2,5,5);
  1773.                 };
  1774.             };
  1775.         };
  1776.         SetAPen(rpG,1L);
  1777. }
  1778.  
  1779. /*************************************************************************/
  1780.  
  1781. void    map_show_borders(struct RastPort        *rpG)
  1782. {
  1783.         int     i,max,x,y;
  1784.         VECT    *v;
  1785.         char    Buffer[10];
  1786.  
  1787.         SetDrMd(rpG,JAM2);
  1788.         SetAPen(rpG,11L);
  1789.         for(i=0;i<max_border;i++){
  1790.             if(tstclip( Pref.clip_cur.minx,Pref.clip_cur.miny,
  1791.                         Pref.clip_cur.maxx,Pref.clip_cur.maxy,&(tab_vect[i].b_clip))){
  1792.                 v=tab_vect[i].p_vect;
  1793.  
  1794.                 x=v[0].x;
  1795.                 y=v[0].y;
  1796.                 conv_xy(&x,&y);
  1797.                 map_draw_rect(rpG,x-2,y-2,5,5);
  1798.                 max=tab_vect[i].nb_vect-1;
  1799.                 x=v[max].x;
  1800.                 y=v[max].y;
  1801.                 conv_xy(&x,&y);
  1802.                 map_draw_rect(rpG,x-2,y-2,5,5);
  1803.  
  1804.                 sprintf(Buffer,"%d",i);
  1805.                 x=v[0].x;
  1806.                 y=v[0].y;
  1807.                 conv_xy(&x,&y);
  1808.                 MyMove(rpG,x+5,y+5);
  1809.                 Text(rpG,Buffer,strlen(Buffer));
  1810.             };
  1811.         };
  1812.         SetAPen(rpG,1L);
  1813. }
  1814.  
  1815. /*************************************************************************/
  1816.  
  1817. void    map_show_bords(int country_sel,int start_bord,struct RastPort *rpG)
  1818. {
  1819.         int     i,num_bord;
  1820.         VECT    *v;
  1821.  
  1822.         num_bord=(tab_country[country_sel].p_borders)[start_bord];
  1823.         /*printf("cmd schow bord de %d\n",num_bord);*/
  1824.         SetAPen(rpG,10);
  1825.         v=tab_vect[num_bord].p_vect;
  1826.         for(i=0;i<tab_vect[num_bord].nb_vect;i++){
  1827.                 if(i==0){
  1828.                         MyMove(rpG,v->x,v->y);
  1829.                 }else{
  1830.                         MyDraw(rpG,v->x,v->y,v->Code);
  1831.                 }
  1832.                 v++;
  1833.         }
  1834. }
  1835.  
  1836. /*************************************************************************/
  1837.  
  1838. void    map_reset_zoom(struct RastPort *rpG)
  1839. {
  1840.         Pref.clip_cur=clip_max;
  1841.         Pref.prof=Find_Profondeur(Pref.prof_real);
  1842.         redraw_map(-1,rpG);
  1843. }
  1844.  
  1845. /*************************************************************************/
  1846.  
  1847. void    exchg(int       *a,int  *b)
  1848. {
  1849.         int     t;
  1850.         t=*a;
  1851.         *a=*b;
  1852.         *b=t;
  1853. }
  1854.  
  1855. /*************************************************************************/
  1856. void map_set_zoom(struct RastPort       *rpG,
  1857.                 int     sx,int sy,
  1858.                 int     lx,int ly
  1859.                 )
  1860. {
  1861.         int     minxt,minyt,maxxt,maxyt;
  1862.  
  1863.         minxt=sx;
  1864.         minyt=sy;
  1865.         maxxt=lx;
  1866.         maxyt=ly;
  1867.         conv_inv_xy(&minxt,&minyt);
  1868.         conv_inv_xy(&maxxt,&maxyt);
  1869.         /* Il faut faire une copie temporaire de minx...maxy */
  1870.         /* car ce sont des variables globales utilisee par   */
  1871.         /* conv_in                                                                                   */
  1872.         if(minxt>maxxt)exchg(&minxt,&maxxt);
  1873.         if(minyt>maxyt)exchg(&minyt,&maxyt);
  1874.         Pref.clip_cur.minx=minxt;
  1875.         Pref.clip_cur.miny=minyt;
  1876.         Pref.clip_cur.maxx=maxxt;
  1877.         Pref.clip_cur.maxy=maxyt;
  1878.         /*printf("minx:%d miny:%d maxx:%d maxy:%d\n",minxt,minyt,maxxt,maxyt);*/
  1879.         Pref.prof=Find_Profondeur(Pref.prof_real);
  1880.         redraw_map(-1,rpG);
  1881. }
  1882.  
  1883. /*************************************************************************/
  1884. void map_move(struct RastPort   *rpG,
  1885.                 int     sx,int sy
  1886.                 )
  1887. {
  1888.     int SX; /*=sx*(Pref.clip_cur.maxx-Pref.clip_cur.minx)/100;*/
  1889.     int SY; /*=sy*(Pref.clip_cur.maxy-Pref.clip_cur.miny)/100;*/
  1890.         int X1=Pref.clip_cur.maxx;
  1891.         int X2=Pref.clip_cur.minx;
  1892.         int Y1=Pref.clip_cur.maxy;
  1893.         int Y2=Pref.clip_cur.miny;
  1894.  
  1895.         if (Pref.Type_Proj==PROJ_GLOBE)
  1896.         {
  1897.                 map_center(rpG,
  1898.                         ((50-sx)*Pref.clip_cur.minx
  1899.                                         +(50+sx)*Pref.clip_cur.maxx)/100,
  1900.                         ((50-sy/2)*Pref.clip_cur.miny
  1901.                                         +(50+sy/2)*Pref.clip_cur.maxy)/100);
  1902.         }
  1903.         else
  1904.         {
  1905.                 conv_xy(&X1,&Y1);
  1906.                 conv_xy(&X2,&Y2);
  1907.                 SX=sx*(X1-X2)/100;
  1908.                 SY=sy*(Y1-Y2)/100;
  1909.                 X1+=SX;
  1910.                 Y1+=SY;
  1911.                 Y2+=SY;
  1912.                 X2=(Pref.win_width)*(Y2-Y1)/(Pref.win_height)+X1;
  1913.                 conv_inv_xy(&X1,&Y1);
  1914.                 conv_inv_xy(&X2,&Y2);
  1915.         Pref.clip_cur.minx=X2;
  1916.         Pref.clip_cur.maxx=X1;
  1917.         Pref.clip_cur.miny=Y2;
  1918.         Pref.clip_cur.maxy=Y1;
  1919.                 correct_clip(&Pref.clip_cur);    
  1920.                 conv_clip();
  1921.                 redraw_map(-1,rpG);
  1922.         }
  1923. }
  1924.  
  1925. /*************************************************************************/
  1926. void map_center(struct RastPort *rpG,
  1927.                 int     X,
  1928.                 int Y
  1929.                 )
  1930. {
  1931.         int sx=(Pref.clip_cur.maxx-Pref.clip_cur.minx)/2;
  1932.         int sy=(Pref.clip_cur.maxy-Pref.clip_cur.miny)/2;
  1933.     Pref.clip_cur.minx=X-sx;
  1934.     Pref.clip_cur.maxx=X+sx;
  1935.     Pref.clip_cur.miny=Y-sy;
  1936.     Pref.clip_cur.maxy=Y+sy;
  1937.         conv_clip();    
  1938.         redraw_map(-1,rpG);
  1939. }
  1940.  
  1941.  
  1942. /***************************************************** redraw_map() *****/
  1943. /*************************************************************/
  1944. /* Reaffiche la carte, mais avec des donnees sur cette carte */
  1945. /*************************************************************/
  1946.  
  1947. void redraw_map_data(
  1948.         struct  RastPort        *rpG
  1949.         )
  1950. {
  1951.         struct RastPort *r;
  1952.         int     num_country;
  1953.  
  1954.  
  1955.         r = rpG;
  1956.         SetRast(r,COLOR_BLEU+num_first_color);
  1957.         SetBPen(r,COLOR_COTE+num_first_color);
  1958.         SetDrMd(r,JAM1);
  1959.  
  1960.         reset_bord();
  1961.         /********************************************/
  1962.         /* Pour tout les pays selectionnes          */
  1963.         /********************************************/
  1964.  
  1965.         for(num_country=0;num_country<max_country;num_country++){
  1966.                 
  1967.                 
  1968.         }/* Fin du for sur les country          */
  1969.  
  1970. }
  1971.  
  1972. void    Map_Set_Spread_Colors(struct ViewPort *vp)
  1973. {
  1974.         int     i;
  1975.         UWORD   r,g,b;
  1976.  
  1977.         for(i=0;i<(nb_colors_free-2);i++){
  1978.                 r=16-i;
  1979.                 g=r;
  1980.                 b=r/2;
  1981.                 SetRGB4(vp,i+num_first_color+2,r,g,b);
  1982.         }
  1983.         
  1984. }
  1985.  
  1986. /****************************************************/
  1987. /* Fonction a appeler pour initialiser un graphique */
  1988. /****************************************************/
  1989. /* Cette fonction retourne le nombre de plage dispo */
  1990. /* suivant le type de graphique demandee, et le     */
  1991. /* nombre de couleur dispo                          */
  1992.  
  1993. void Map_Init_Graph(struct RastPort *rpG,char *Titre)
  1994. {
  1995.         /*printf("Map_Init_Graph\n");*/
  1996.  
  1997.         if (Titre_Font_Glob)
  1998.             SetFont(rpG,Titre_Font_Glob);
  1999.             SetSoftStyle(rpG,(FSF_BOLD | FSF_UNDERLINED | FSF_ITALIC),
  2000.                 (FSF_BOLD ));
  2001.  
  2002.             IPrint(rpG,Pref.win_width/10,30,Titre,-1);
  2003.     if (Text_Font_Glob)
  2004.         SetFont(rpG,Text_Font_Glob);
  2005.         if(Pref.Flg_Proj_3D==FALSE)SetRast(rpG,0L);
  2006.  
  2007. /*
  2008.         Map_Set_Spread_Colors(vp_glob);
  2009. */      
  2010. }
  2011.  
  2012. /****************************************************/
  2013. /* Nouvelle donnee a afficher                       */
  2014. /****************************************************/
  2015.  
  2016. void Map_Aff_Data_3D(struct RastPort *rpG,DATA_TRI *Data_Tri,int value)
  2017. {
  2018.         static  int     Tab_Pt[][3]={
  2019.                 {-2,-2,  0},{-2,2,  0},{ 2,2,  0},{ 2,-2,  0},
  2020.                 {-2,-2,200},{-2,2,200},{ 2,2,200},{ 2,-2,200}
  2021.                         };
  2022.         static  int     Tab_Faces[6][5]=
  2023.                 {
  2024.                 {0,1,2,3,4},
  2025.                 {0,3,5,4,5},
  2026.                 {3,2,6,7,6},
  2027.                 {2,1,5,6,7},
  2028.                 {1,0,4,5,8},
  2029.                 {7,6,5,4,9}
  2030.                 };
  2031.         static  int     Tab_Pt_2d[100][2];
  2032.  
  2033.         int     i,j,x,y,z,xc,yc,xe,ye,n,n1,n2,n3;
  2034.         CLIP    *clip;
  2035.  
  2036.            if(value>0){
  2037.                 
  2038.                 fill_country(Data_Tri->Num_Pays,value,rpG);
  2039.                 Pref.Flg_Proj_3D=FALSE;
  2040.                 clip=&tab_country[Data_Tri->Num_Pays].c_clip;
  2041.                 xc=(clip->maxx+clip->minx)/2;
  2042.                 yc=(clip->maxy+clip->miny)/2;
  2043.                 conv_xy(&xc,&yc);
  2044.                 
  2045.                 Tab_Pt[4][2]=-value*5;
  2046.                 Tab_Pt[5][2]=-value*5;
  2047.                 Tab_Pt[6][2]=-value*5;
  2048.                 Tab_Pt[7][2]=-value*5;
  2049.  
  2050.                 for(i=0;i<8;i++){
  2051.                         x=Tab_Pt[i][0]+xc;
  2052.                         y=Tab_Pt[i][1]+yc;
  2053.                         z=Tab_Pt[i][2];
  2054.                         
  2055.                         T3D_ConvertZ(x,y,z,&xe,&ye);
  2056.                         Tab_Pt_2d[i][0]=xe;
  2057.                         Tab_Pt_2d[i][1]=ye;
  2058.                 }
  2059.                 for(j=0;j<6;j++){
  2060.                 {
  2061.                         n1=Tab_Faces[j][0];
  2062.                         n2=Tab_Faces[j][1];
  2063.                         n3=Tab_Faces[j][2];
  2064.  
  2065.                         if((( Tab_Pt_2d[n2][1] - Tab_Pt_2d[n1][1])*
  2066.                             ( Tab_Pt_2d[n2][0] - Tab_Pt_2d[n3][0])
  2067.                           - ( Tab_Pt_2d[n2][0] - Tab_Pt_2d[n1][0])*
  2068.                             ( Tab_Pt_2d[n2][1] - Tab_Pt_2d[n3][1]))>0){
  2069.  
  2070.                                 SetAPen(rpG,Tab_Faces[j][4]);
  2071.                                 for(i=0;i<4;i++){
  2072.                                         n=Tab_Faces[j][i];
  2073.                                         x=Tab_Pt_2d[n][0];
  2074.                                         y=Tab_Pt_2d[n][1];
  2075.                                         if(i==0){
  2076.                                                 AreaMove(rpG,x,y);
  2077.                                         }else{
  2078.                                                 AreaDraw(rpG,x,y);
  2079.                                         }
  2080.                                 }
  2081.                                 AreaEnd(rpG);
  2082.                         }
  2083.                                                                                                                 }
  2084.                 }
  2085.                 Pref.Flg_Proj_3D=TRUE;
  2086.               }
  2087.  
  2088. }
  2089.  
  2090. /****************************************************/
  2091.  
  2092. void Map_Aff_Data(struct RastPort *rpG,DATA_TRI *Data_Tri,int value)
  2093. {
  2094.         /*int   num;*/
  2095.         int py,num_pays;
  2096.         char    Buffer[100];
  2097.         int     Val;
  2098.         int     debx=220;
  2099.         
  2100.         if(Pref.Flg_Proj_3D==FALSE){
  2101.            if(Data_Tri->valeur.data_int!=0){
  2102.                 num_pays=Data_Tri->Num_Pays;
  2103.                 py=Data_Tri->Rang*10+60;
  2104.                 IPrint(rpG,10,py,tab_country[num_pays].name,-1);
  2105.                 SetAPen(rpG,7);
  2106.                 SafeSetOutlinePen(rpG,6);
  2107.                 Val=debx+(int)((float)(Data_Tri->valeur.data_int))*((float)(Pref.win_width-(debx+20)))/Pref.Glob_Max;
  2108.  
  2109.                 if(Glob_Type==GRAPH_BAR){
  2110.                         RectFill(rpG,debx,py-7,Val,py);
  2111.                 }
  2112. /*              RectFill(rpG,200,py,200+Data_Tri->valeur.data_int/100,py+7);*/
  2113.                 sprintf(Buffer,"%d",Data_Tri->valeur.data_int);
  2114.                 IPrintFond(rpG,150,py,Buffer,-1);
  2115.                 BNDRYOFF(rpG);
  2116.            }
  2117.         }else{
  2118.                 Map_Aff_Data_3D(rpG,Data_Tri,value);
  2119.         }
  2120. }
  2121.  
  2122. /****************************************************/
  2123.  
  2124. void    Map_End_Graph(struct RastPort *rpG)
  2125. {
  2126.         /*printf("Map_End_Graph\n");*/
  2127.         /*Aff_Error("Graph ok","End");*/
  2128.  
  2129.         /*printf("Map_End_Graph\n");*/
  2130. }
  2131.  
  2132. /****************************************************/
  2133.  
  2134. void    Map_Set_Default_Colors(struct ViewPort *vp)
  2135. {
  2136.         static  BOOL    Flg_First=TRUE;
  2137.         static  ULONG   *Palette_Deb;
  2138.         int     i;
  2139.         UWORD   r,g,b;
  2140.  
  2141.         static UWORD Palette[]={
  2142.                 0x0ff,          /* 0= Bleu Mer */
  2143.                 0x0f0,          /* 1=vert*/
  2144.                 0x06f,          /* 2=Rivers     bleu foncé*/
  2145.                 0x00f,          /* 3=Lakes      */
  2146.                 0x085,          /* 4=state      */              
  2147.                 0xd74,          /* 5=brun frontieres*/
  2148.                 0xf00,          /* 6=rouge   pour les dégradés*/
  2149.                 0xf66,          /* 7=rouge 2*/
  2150.                 0xf98,          /* 8=rouge 3*/
  2151.                 0xc98,          /* 9=rouge 4*/
  2152.                 0xd83,          /* 10=rouge 5*/
  2153.                 0xdb3           /* 11=rouge 6*/
  2154.         };
  2155.         if(Flg_First){
  2156.                 Flg_First=FALSE;
  2157.                 Palette_Deb=(ULONG *)malloc(num_first_color*sizeof(ULONG));
  2158.                 if(Palette_Deb){
  2159.                         for (i=0;i<num_first_color;i++){
  2160.                                 Palette_Deb[i]=GetRGB4(vp->ColorMap,i);
  2161.                         }
  2162.                 }
  2163.         }else{
  2164.  
  2165.             if(Palette_Deb){
  2166.                 for (i=0;i<num_first_color;i++)
  2167.                 {
  2168.                         r=( Palette_Deb[i]>>8 )& 0x0F;
  2169.                         g=( Palette_Deb[i]>>4 )& 0x0F;
  2170.                         b=( Palette_Deb[i]>>0 )& 0x0F;
  2171.                         SetRGB4(vp,i,r,g,b);
  2172.                 }
  2173.            }
  2174.  
  2175.         }
  2176.  
  2177.         for (i=0;i<nb_colors_free;i++)
  2178.     {
  2179.                 r=( Palette[i]>>8 )& 0x0F;
  2180.                 g=( Palette[i]>>4 )& 0x0F;
  2181.                 b=( Palette[i]>>0 )& 0x0F;
  2182.                 SetRGB4(vp,i+num_first_color,r,g,b);
  2183.         }
  2184.         vp_glob=vp;     
  2185. }
  2186.  
  2187. /****************************************************/
  2188.  
  2189. int  Map_Get_Plages(    struct  RastPort *rpG   ,
  2190.                         int     plages_dem      ,
  2191.                         E_Type_Data Type        ,
  2192.                         int nb_data,
  2193.                         int     min             ,
  2194.                         int     max             ,
  2195.                         E_Type_Graph In_Type
  2196.                 )
  2197. {
  2198.         Type_Data_Glob=Type;
  2199.         Pref.Glob_Min=min;
  2200.         Pref.Glob_Max=max;
  2201.         Glob_Type=In_Type;
  2202.         return(10);
  2203. }
  2204.  
  2205.  
  2206. /****************************************************/
  2207.  
  2208. /* Give default font used to draw information */
  2209.  
  2210. void    Map_Give_Default_Font( 
  2211.         struct TextFont *Titre_Font,
  2212.         struct TextFont *Text_Font
  2213.         )
  2214. {
  2215.         Titre_Font_Glob=Titre_Font;
  2216.         Text_Font_Glob =Text_Font;
  2217. }
  2218.  
  2219. /************************************************************************/
  2220. /* Trace le quadrillage correspondant aux latitudes et longitudes       */
  2221. /************************************************************************/
  2222.  
  2223.  
  2224. void    
  2225. Map_Aff_LatLon(struct RastPort *rpG)
  2226. {
  2227.     int     Lat,Lon;
  2228.     int code;                                
  2229.     if (Pref.Flg_Aff_LatLon)
  2230.     {
  2231.         SetDrPt(rpG,0xCCCC);
  2232.         SetAPen(rpG,COLOR_LATLON+num_first_color);
  2233.         for (Lon=-180;Lon<=180;Lon+=1)
  2234.         {
  2235.             /* traits verticaux */
  2236.             if( (Pref.clip_cur.minx < Lon*100)&& (Pref.clip_cur.maxx > Lon *100))
  2237.             {
  2238.                 if (Lon % 20 == 0)
  2239.                     code = 5;
  2240.                 else
  2241.                 if (Lon % 5 == 0)
  2242.                     code = 4;
  2243.                 else
  2244.                     code = 3;
  2245.                 if (code >= Pref.prof)
  2246.                 {
  2247.                     MyMove(rpG,Lon*100,MAX(Pref.clip_cur.miny,-9000));
  2248.                     for (Lat=MAX(Pref.clip_cur.miny/100,-90);
  2249.                             Lat<=MIN(Pref.clip_cur.maxy/100,90);Lat+=1)
  2250.                     {
  2251.                         short int code2;
  2252.                         if (Lat%20 == 0)
  2253.                             code2=code;
  2254.                         else
  2255.                         if (Lat%5 == 0)
  2256.                             code2=code-1;
  2257.                         else
  2258.                             code2=code-2;
  2259.                         MyDraw(rpG,Lon*100,Lat*100,code2);
  2260.                     }
  2261.                     MyDraw(rpG,Lon*100,MIN(Pref.clip_cur.maxy,9000),5);
  2262.                 }
  2263.             }
  2264.         }
  2265.         for (Lat=-90;Lat<=90;Lat+=1)
  2266.         {
  2267.             if ( (Pref.clip_cur.miny < Lat*100)&& (Pref.clip_cur.maxy > Lat *100))
  2268.             {
  2269.                 if (Lat % 20 == 0)
  2270.                     code = 5;
  2271.                 else
  2272.                 if (Lat % 5 == 0)
  2273.                     code = 4;
  2274.                 else
  2275.                     code = 3;
  2276.                 if (code>=Pref.prof)
  2277.                 {
  2278.                     MyMove(rpG,MAX(Pref.clip_cur.minx,-18000),Lat*100);
  2279.                     for (Lon=MAX(Pref.clip_cur.minx/100,-180);
  2280.                             Lon<=MIN(Pref.clip_cur.maxx/100,180);Lon+=1)
  2281.                     {
  2282.                         short int code2;
  2283.                         if (Lon%20 == 0)
  2284.                             code2=code;
  2285.                         else
  2286.                         if (Lon%5 == 0)
  2287.                             code2=code-1;
  2288.                         else
  2289.                             code2=code-2;
  2290.                         MyDraw(rpG,Lon*100,Lat*100,code2);
  2291.                     }
  2292.                     MyDraw(rpG,MIN(Pref.clip_cur.maxx,18000),Lat*100,5);
  2293.                 }
  2294.             }
  2295.         }
  2296.         SetDrPt(rpG,0xFFFF);
  2297.     }
  2298. }
  2299.  
  2300. void    Map_Aff_Fond(char *pc,struct Screen *sC)
  2301. {
  2302.         Map_Del_Fond();
  2303.  
  2304.         Object_Fond=Iff_New_Charge_Iff(pc,sC);
  2305.  
  2306. }
  2307. /********** Del Screen Image *****************************/
  2308. void Map_Del_Fond(void)
  2309. {
  2310.         if(Object_Fond){
  2311.                 Iff_Free_Obj(Object_Fond);
  2312.         }
  2313.         Object_Fond=NULL;
  2314. }
  2315.  
  2316.  
  2317. void Map_Aff_Echelle(struct RastPort * rpG)
  2318. {
  2319.         char zero[4];
  2320.         char cent[15];
  2321.         int y=(Pref.clip_cur.maxy+Pref.clip_cur.miny)/2;
  2322.         int sx=Pref.clip_cur.maxx-Pref.clip_cur.minx;
  2323.         float alpha=Map_Convert_Angle(y);
  2324.         int perimetre=2*PI*RAYON;
  2325.         long int largeur=perimetre*sx*cos(alpha)/36000;
  2326.         int puissance=log10(0.9*largeur);
  2327.         int max_echelle=pow(10.0,(double)puissance);
  2328.         int longueur_echelle=max_echelle*sC->Width/largeur;
  2329.         SetAPen(rpG,COLOR_TEXTE);
  2330.         Move(rpG, 10,(sC->Height)-20);
  2331.         Draw(rpG, 10+longueur_echelle,(sC->Height)-20);
  2332.         Move(rpG, 10,(sC->Height)-23);
  2333.         Draw(rpG, 10,sC->Height-17);
  2334.         Move(rpG, 10+longueur_echelle,sC->Height-23);
  2335.         Draw(rpG, 10+longueur_echelle,sC->Height-17);
  2336.         sprintf(zero,"0");
  2337.         IPrintFond(rpG, 6, sC->Height-25,zero,COLOR_TEXTE);
  2338.         sprintf(cent,"%d km",max_echelle);
  2339.         IPrintFond(rpG, 10+longueur_echelle-strlen(cent)*4,sC->Height-25,cent,
  2340.                         COLOR_TEXTE);
  2341. }
  2342.  
  2343. void Map_Aff_Trajectoires(struct RastPort * rpG,TRAJECTOIRE ** tableau)
  2344. /* affiche les trajectoires d'un tableau*/
  2345. /* si tableau==NULL, on prend tab_trajectoire*/
  2346. {
  2347.     int num_traj=0;
  2348.     int j;
  2349.     if (tableau==NULL)
  2350.             tableau=tab_trajectoire;
  2351.     while (tableau[num_traj]!=NULL)
  2352.     {
  2353.         if (tstclip(        Pref.clip_cur.minx,Pref.clip_cur.miny,
  2354.                     Pref.clip_cur.maxx,Pref.clip_cur.maxy,
  2355.                     &(tableau[num_traj]->clip)))
  2356.         {
  2357.                     VECT *V=tableau[num_traj]->vecteurs;
  2358.                     SetAPen(rpG,6+num_first_color);
  2359.             MyMove(rpG,V[0].x,V[0].y);
  2360.             for (j=1;j<tableau[num_traj]->nb_vect;j++)
  2361.             {
  2362.                     MyDraw(rpG,V[j].x,V[j].y,V[j].Code);
  2363.             }
  2364.         }
  2365.         num_traj++;
  2366.     }
  2367. }
  2368.  
  2369.